package tk.cful.ejb;

import tk.cful.core.DBManager;
import tk.cful.core.UserEntity;

import javax.ejb.CreateException;
import javax.ejb.Local;
import javax.ejb.Stateful;
import java.sql.SQLException;

/**
 * User: Root
 * Date: 08.11.13
 * Time: 18:46
 */
@Stateful(name = "UserManagerEJB")
@Local(UserManagerLocal.class)
public class UserManagerBean {

    public UserManagerBean() {
    }

    public void ejbCreate() throws CreateException {

    }

    public boolean login(String userName, String password) {
        DBManager manager = DBManager.getInstance();
            UserEntity ue = manager.findUserByName(userName);
            if (ue == null)
                return false;
            if (ue.getPassword().equals(password))
                return true;
        return false;
    }

    public boolean register(String userName, String password) {
        DBManager manager = DBManager.getInstance();
        return manager.addUser(manager.generateUserID(), userName, password);
    }

}
